//
//  KFDAliveNewsPiece.m
//  
//
//  Created by JIRENTIANXIANG on 6/12/15.
//
//

#import "KFDLiveNewsPiece.h"
#import "ui_config.h"

@implementation KFDLiveNewsPiece

-(instancetype)initWithDictionary:(NSDictionary *)dictionary
{
    if (self=[super initWithDictionary:dictionary]) {
        NSString* color=dictionary[@"color"];
        if (color&&color.length==7) {
            NSString* r=[color substringWithRange:NSMakeRange(1, 2)];
            NSString* g=[color substringWithRange:NSMakeRange(3, 2)];
            NSString* b=[color substringWithRange:NSMakeRange(5, 2)];
            self.color=KFDColorRGB([self hexFromString:r], [self hexFromString:g], [self hexFromString:b]);
        }else{
            self.color=nil;
        }
        self.isbold=[dictionary[@"isbold"] isEqualToString:@"1"]?YES:NO;
    }
    return self;
}

-(unsigned)hexFromString:(NSString*)str
{
    unsigned hex;
    NSScanner* scanner=[NSScanner scannerWithString:str];
    [scanner setScanLocation:0];
    [scanner scanHexInt:&hex];
    return hex;
}

@end
